package application

import (
	"github.com/jinzhu/gorm"
	"time"
)

//CREATE TABLE `voices` (
// `id` int(11) NOT NULL AUTO_INCREMENT,
// `appid` varchar(255) DEFAULT NULL,
// `access_token` varchar(255) DEFAULT NULL,
// `cluster` varchar(255) DEFAULT NULL,
// `voice_type` varchar(255) DEFAULT NULL,
// `name` varchar(255) DEFAULT NULL,
// `api_url` varchar(255) DEFAULT NULL,
// `created_at` datetime DEFAULT NULL,
// `updated_at` datetime DEFAULT NULL,
// PRIMARY KEY (`id`)
//) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

type Voice struct {
	Id          int       `json:"id" gorm:"column:id;primary_key"`
	AppId       string    `json:"app_id" gorm:"column:app_id"`
	AccessToken string    `json:"access_token" gorm:"column:access_token"`
	Cluster     string    `json:"cluster" gorm:"column:cluster"`
	VoiceType   string    `json:"voice_type" gorm:"column:voice_type"`
	Name        string    `json:"name" gorm:"column:name"`
	ApiUrl      string    `json:"api_url" gorm:"column:api_url"`
	CreatedAt   time.Time `json:"created_at" gorm:"column:created_at"`
	UpdatedAt   time.Time `json:"updated_at" gorm:"column:updated_at"`
}

func (v *Voice) TableName() string {
	return "voices"
}
func (v *Voice) Create(db *gorm.DB) error {
	return db.Table(v.TableName()).Create(v).Error
}

func (v *Voice) GetVoiceList(db *gorm.DB) (voices []Voice, err error) {
	err = db.Table(v.TableName()).Find(&voices).Error
	return
}
